package web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import dao.CommentDAO;

import beans.Comment;
import beans.User;

public class CommentController {

	private LoggedUser loggedUser;
	public void setLoggedUser(LoggedUser loggedUser) {
		this.loggedUser = loggedUser;
	}
	private CommentDAO commentDAO;
	
	

	public void setCommentDAO(CommentDAO commentDAO) {
		this.commentDAO = commentDAO;
	}
	
	@RequestMapping(value = "/addcommentrestaurantid={restaurantId}", method=RequestMethod.POST)
	public ModelAndView addcomment(@PathVariable("restaurantId") int id, HttpServletRequest request,
			HttpServletResponse response, Comment comment) throws Exception {
		User user = loggedUser.getLoggedUser();
		comment.setUsername(user.getUsername());
		comment.setRestaurant_id(id);
		commentDAO.saveComment(comment);
		return new ModelAndView("redirect:restaurantid="+id+".htm");
	}
}
